/*
* 总计渲染
* */
const setTotal = (param, array, typeIndex) => { // 渲染总计参数 不需要替换的index 指定分转换成元的index
  const { columns, data } = param
  const sums = []
  columns.forEach((column, index) => {
    if (index === 0) {
      sums[index] = '合计'
      return
    }
    const values = data.map(item => Number(item[column.property]))
    if (!values.every(value => isNaN(value))) {
      sums[index] = values.reduce((prev, curr) => {
        const value = Number(curr)
        if (!isNaN(value)) {
          return prev + curr
        } else {
          return prev
        }
      }, 0)
      sums[index]
    } else {
      sums[index] = 'N/A'
    }
  })
  // 替换
  for (let i = 0; i < array.length; i++) {
    sums[array[i]] = 'N/A'
  }
  sums[typeIndex] = sums[typeIndex] / 100
  return sums
}

export default setTotal
